package lcr;

public class Test0091 {
    public static void main(String[] args) {
        new Solution0091_1().minCost(new int[][]{{17,2,17},
                {16,16,5},{14,3,19}});
    }
}

class Solution0091_1 {
    public int minCost(int[][] costs) {
        int[] dp = costs[0],temp=new int[3];

        for (int i = 1; i < costs.length; i++) {
            int[] cost = costs[i];
            temp[0]=Math.min(dp[1],dp[2])+cost[0];
            temp[1]=Math.min(dp[0],dp[2])+cost[1];
            temp[2]=Math.min(dp[0],dp[1])+cost[2];

            int[] dp1 = dp;
            dp=temp;
            temp=dp1;
        }

        return Math.min(dp[0], Math.min(dp[1], dp[2]));
    }
}
